import com.lishanyang.hibernate.dao.UserAnnotationsEnityDAO;
import com.lishanyang.hibernate.dao.UserAnnotationsEnityDAOImpl;
import com.lishanyang.hibernate.dao.UserDAO;
import com.lishanyang.hibernate.dao.UserDAOImpl;
import com.lishanyang.hibernate.entity.UserAnnotationsEntity;
import com.lishanyang.hibernate.entity.UserEntity;

public class TestUser {
    public static void main(String[] args){
        TestUser testUser=new TestUser();
        testUser.testAdd();
//        testUser.testUpdate(16);
//        testUser.testAddUserAnnotationEntity();
    }

    protected void testAddUserAnnotationEntity(){
        UserAnnotationsEntity userAnnotationsEntity=new UserAnnotationsEntity();
        userAnnotationsEntity.setAddr("科学大道100号！");
        userAnnotationsEntity.setName("李山羊");
        UserAnnotationsEnityDAO userAnnotationsEnityDAO=new UserAnnotationsEnityDAOImpl();
        userAnnotationsEnityDAO.addUserAnnotationsEnity(userAnnotationsEntity);
    }

    protected void testAdd(){
        UserEntity userEntity=new UserEntity();
        userEntity.setName("李大大");
        userEntity.setAge(28);
        userEntity.setAddr("杭州市余杭区中泰街道星未来云邸17-2-601");
        UserDAO userDAO=new UserDAOImpl();
        userDAO.add(userEntity);
    }
    protected void testUpdate(int i){
        UserDAO userDAO=new UserDAOImpl();
        UserEntity userEntity=userDAO.get(i);
        if(userEntity!=null){
            userEntity.setAddr("杭州市余杭区中泰街道星未来云邸17-2-601");
            userDAO.update(userEntity);
            System.out.println("更新成功！");
        }else {
            userEntity.setAddr("杭州市余杭区中泰街道星未来云邸17-2-601");
            userDAO.update(userEntity);
        }
    }
}
